import 'package:get/get.dart';
import 'package:xin_he/page/mine/xin_he_mine_team/xin_he_team_extend_item_entity.dart';
import 'package:xin_he/utils/xin_he_toast.dart';
import 'package:xin_he/utils/xin_he_user_data.dart';

import '../../../service/xin_he_reqest.dart';
import '../../../utils/xin_he_storage.dart';
import 'xin_he_mine_team_state.dart';

class XinHeMineTeamLogic extends GetxController {
  final XinHeMineTeamState state = XinHeMineTeamState();
  RxList derictDataList = [].obs;
  RxList notDerictdataList = [].obs;
  RxList currentList = [].obs;
  RxInt currentIndex = 0.obs;
  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();

    requestMyPushMember();
    requestMyJianTuiPushMember();
    requestMyTeam();

    currentList = derictDataList;
  }


  requestMyTeam() async{
    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);

    Map<String,dynamic>map = {

      'userId':11818469275471873

    };
    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/member/findByMemberTeam',params: map,isPost: false);

    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }
    if(result.data['code'] == 0){
      state.totalPeople.value = result.data['data']['totalPeople'];
      state.totalPerformance.value = '${result.data['data']['totalPerformance']}';
    }else {
      XinHeToast.center(result.data['message']);
    }

  }

  //、直推
  requestMyPushMember() async{
    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);

    Map<String,dynamic>map = {
      'userId':11818469275471873
    };
    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/member/findByMemberDirectPush',params: map,isPost: false);

    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }
    List list = result.data['data']??[];
    List modelArr = [];
    if(list.isNotEmpty) {
      for(var e in list) {
        XinHeTeamExtendItemEntity model = XinHeTeamExtendItemEntity.fromJson(e);
        modelArr.add(model);
      }
      derictDataList.value = modelArr;
    }


  }


  //jian推
  requestMyJianTuiPushMember() async{
    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);

    Map<String,dynamic>map = {
      'userId':11818469275471873
    };
    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/member/findByMemberInterpenetration',params: map,isPost: false);

    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }
    List list = result.data['data']??[];
    List modelArr = [];
    if(list.isNotEmpty) {
      for(var e in list) {
        XinHeTeamExtendItemEntity model = XinHeTeamExtendItemEntity.fromJson(e);
        modelArr.add(model);
      }
      notDerictdataList.value = modelArr;
    }


  }


  changeTabIndex(int index) {
    currentIndex.value = index;
    if(index == 0) {
      currentList.value = derictDataList.value;
    }else {
      currentList.value = notDerictdataList.value;
    }
  }




}
